/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package transformer;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Rishav
 */
public class PatternExtract implements Transformer {

    private String data;

    @Override
    public void setData(String data) {
        this.data = data;
    }

    @Override
    public String evaluate(String... args) {
        if (args.length != 1) {
            return "";
        } else {
            Pattern p = Pattern.compile(args[0]);
            Matcher m = p.matcher(data);
            if (m.find()) {
                return m.group(1);
            }
            return "Pattern Not Found";
        }
    }

}
